import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for(int i=0;i<t;i++) {
            int n = in.nextInt();
            int k = in.nextInt();
            String s = in.next();
            System.out.println(test(n,k,s));
        }
    }
    private static int test(int n,int k,String s) {
        int ret = 0;
        char[] ss = s.toCharArray();
        int prev = 0;
        for(int i=0;i<n;i++) {
            if(ss[i] == 'W') {
                if(i-prev+1 >= 3) {
                    ret += k;
                } else {
                    ret++;
                }
            } else {
                prev = i+1;
                ret--;
            }
        }
        return ret;
    }
}